package android.slc.appbase.ui.fragment.base;

import android.os.Bundle;
import android.slc.appbase.config.ConstantsBase;
import android.slc.appbase.R;
import android.slc.appbase.vm.AppBaseViewModel;
import android.slc.toolbar.ISlcToolBarDelegate;
import android.slc.toolbar.SlcToolBarDelegate;

import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.appcompat.widget.Toolbar;
import androidx.databinding.ViewDataBinding;

import com.blankj.utilcode.util.StringUtils;

public abstract class AppMvvmBaseToolBarFragment<V extends ViewDataBinding, VM extends AppBaseViewModel> extends AppMvvmBaseFragment<V, VM> {
    protected Toolbar mSlcToolbar;

    protected String getTitleByArguments(String defTitle) {
        if (getArguments() != null) {
            String titleByIntent = getArguments().getString(ConstantsBase.Key.KEY_TITLE_LABEL);
            if (StringUtils.isEmpty(titleByIntent)) {
                titleByIntent = defTitle;
            }
            return titleByIntent;
        }
        return defTitle;
    }

    protected String getTitleByArguments(@StringRes int defTitleId) {
        return getTitleByArguments(StringUtils.getString(defTitleId));
    }

    @Override
    public void onBindView(@Nullable Bundle savedInstanceState) {
        super.onBindView(savedInstanceState);
        mSlcToolbar = mSlcToolBarDelegate.getToolBar();
        mSlcToolbar.setNavigationIcon(R.drawable.ic_slc_native_back_light);
        mSlcToolbar.setNavigationOnClickListener(l -> getActivity().onBackPressed());
        mSlcToolBarDelegate.getTitleTextView().setTextSize(18);
        mSlcToolBarDelegate.getSubTitleTextView().setTextSize(12);

    }

    @Override
    protected ISlcToolBarDelegate onInitSlcToolBarDelegate() {
        return new SlcToolBarDelegate.Builder(getContentView()).build();
    }
}
